<template>
  <el-table
    v-loading="listLoading"
    :data="obj.cms"
    border
    highlight-current-row
    style="width: 100%;"
  >
    <el-table-column
      label="编号"
      align="center"
      width="90px"
      type="index"
      :index="indexMethod"
    />
    <el-table-column label="企业" align="center" :show-overflow-tooltip="true">
      <template slot-scope="{row, $index}">
        <span>{{ $index | entFilter(obj.enterprise) }}</span>
      </template>
    </el-table-column>
    <el-table-column label="基地" align="center" :show-overflow-tooltip="true">
      <template slot-scope="{row, $index}">
        <span>{{ $index | siteFilter(obj.site) }}</span>
      </template>
    </el-table-column>
    <el-table-column label="地块" align="center" :show-overflow-tooltip="true">
      <template slot-scope="{row, $index}">
        <span>{{ $index | placeFilter(obj.place) }}</span>
      </template>
    </el-table-column>
    <el-table-column label="账号" align="center" :show-overflow-tooltip="true">
      <template slot-scope="{row}">
        <span>{{ row.account }}</span>
      </template>
    </el-table-column>
    <el-table-column label="用户名" align="center" :show-overflow-tooltip="true">
      <template slot-scope="{row, $index}">
        <span>{{ $index | accountNameFilter(obj.account) }}</span>
      </template>
    </el-table-column>
    <el-table-column
      v-if="typeFlag"
      label="申请时间"
      align="center"
      :show-overflow-tooltip="true"
    >
      <template slot-scope="{row}">
        <span>{{ row.createDate | dateFilter }}</span>
      </template>
    </el-table-column>
    <el-table-column
      v-else
      label="审核时间"
      align="center"
      :show-overflow-tooltip="true"
    >
      <template slot-scope="{row}">
        <span>{{ row.checkDate | dateFilter }}</span>
      </template>
    </el-table-column>
    <el-table-column label="状态" align="center" :show-overflow-tooltip="true">
      <template slot-scope="{row}">
        <span>{{ row.type }}</span>
      </template>
    </el-table-column>
    <el-table-column
      v-if="typeFlag"
      label="操作"
      align="center"
      min-width="110px"
      class-name="small-padding fixed-width"
    ><template slot-scope="{row}">
      <el-button
        type="success"
        size="mini"
        @click.native="permit(row.id)"
      >通过</el-button>
      <el-button
        type="danger"
        size="mini"
        @click.native="refuse(row.id)"
      >拒绝</el-button>
    </template>
    </el-table-column>
  </el-table>
</template>

<script>
import store from '@/store'

export default {
  name: 'MyTable',
  filters: {
    entFilter(index, list) {
      return list[index].entName
    },
    siteFilter(index, list) {
      return list[index].siteName
    },
    placeFilter(index, list) {
      return list[index].placeName
    },
    accountNameFilter(index, list) {
      return list[index].userName
    },
    dateFilter(date) {
      return date === '' ? '暂无' : date.substring(0, 11)
    }
  },
  props: {
    tableValue: {
      type: Array,
      required: true
    },
    typeValue: {
      type: Number,
      required: true
    },
    listLoading: {
      type: Boolean,
      required: true
    }
  },
  data() {
    return {
    }
  },
  computed: {
    typeFlag() {
      return this.typeValue === 0
    },
    obj() {
      return this.tableValue[this.typeValue]
    }
  },
  // watch: {
  //   tableValue(newValue) {
  //     console.log(newValue[this.typeValue])
  //     this.obj = newValue[this.typeValue]
  //   }
  // },
  methods: {
    permit(id) {
      this.$confirm('是否通过此申请?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.$emit('modify', {
          id,
          type: '已通过',
          remark: ''
        })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消'
        })
      })
    },
    refuse(id) {
      this.$confirm('是否拒绝此申请?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.$emit('modify', {
          id,
          type: '已拒绝',
          remark: ''
        })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消'
        })
      })
    },
    HandleGetBaseManager(site) {
      this.managerDialogVisible = true
      this.managerDialogTitle = site.siteName
      this.site = site
      this.getBaseManager()
    },
    updateManager() {
      this.getBaseManager()
    },
    handleModify(row) {
      this.$emit('modify', row)
    },
    indexMethod(index) {
      return index + 1
    },
    routePages(query, url) {
      this.$router.push({
        path: url,
        query
      })
    }
  }
}
</script>
